package com.grf.hadoop.order_grouping;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class OrderMapper extends Mapper<LongWritable, Text, OrderBean, NullWritable> {

    private OrderBean order = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String  line = value.toString();
        String[] field = line.split(" ");

        order.setId(Integer.parseInt(field[0]));
        order.setPrice(Double.parseDouble(field[2]));
        context.write(order, NullWritable.get());
    }
}
